﻿/*********************************************************************
 版权所有: 版权所有(C) 2009 ,熙软研发部
 模块编号:  RoleManage.aspx.cs
 作    者:范徐超
 编写日期:2009-09-09
 审    核:
 审核日期:
 描    述:规则管理页面
...........................................................................
如果模块有修改，则每次修改添加以下注释(以系统上线后为基准)：

 *********************************************************************/

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using Cisoft.Booking.BLL;
using Cisoft.Booking.Model;

public partial class Business_Booking_RulesManage : WebUI.Page.ManagePage
{
    private RuleBO ruleBO = new RuleBO();
    private RuleMO ruleMO = new RuleMO();
    private int pageCount = -1;

    #region 页面加载事件
    /// <summary>
    /// 页面加载事件
    /// </summary>
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            Bind();
        }
    }
    #endregion

    #region 显示数据 private void GetList()
    /// <summary>
    /// 显示数据
    /// </summary>
    private DataSet GetList()
    {
        DataSet ds = new DataSet();
        #region 将数据存放在缓存中
        //if (Cache["Rule"] == null)
        //{
        //    ds = ruleBO.GetAllList();
        //    if (ds.Tables[0].Rows.Count > 0)
        //    {
        //        Cache.Insert("Rule", ds, null, System.Web.Caching.Cache.NoAbsoluteExpiration, TimeSpan.FromMinutes(1));
        //    }
        //}
        //else
        //{
        //    ds = (DataSet)Cache["Rule"];
        //}
        #endregion
        ds = string.IsNullOrEmpty(txtPropasal.Text.Trim()) ? ruleBO.GetAllList() : ruleBO.GetList(" RuleName like '%" + txtPropasal.Text.Trim() + "%' or RuleCode like '%" + txtPropasal.Text.Trim() + "%' ");
        return ds;
    }
    #endregion

    #region 翻页事件
    /// <summary>
    /// 翻页事件
    /// </summary>
    protected void PagerButtonClick(object sender, EventArgs e)
    {
        PagerEvent(sender, e, gvitem);
        Bind();
    }
    #endregion

    #region 查询事件
    /// <summary>
    /// 查询事件
    /// </summary>
    protected void butlookout_Click(object sender, ImageClickEventArgs e)
    {
        //查询条件
        string condition = txtPropasal.Text.Trim();

        DataTable dt = SelectInDataTable(GetList().Tables[0], "RuleName", condition);
        Bind(dt, gvitem);
    }
    #endregion

    #region 数据绑定并分页
    /// <summary>
    /// 数据绑定并分页
    /// </summary>
    /// <param name="dt">数据源DataTable</param>
    /// <param name="gv">绑定的控件GridView</param>
    private void Bind(DataTable dt, GridView gv)
    {

        pageCount = dt.Rows.Count;

        if (pageCount > 0)
        {
            ViewState["numbers"] = pageCount;
            DataView dv = dt.DefaultView;
            dv.Sort = "RuleID asc";
            gv.DataSource = dv.ToTable();
            gv.DataBind();
            div_pager.Visible = true;
            butState(gv, btnFirst, btnPrev, btnNext, btnLast);
            ShowStats(gv, lblCurrentIndex, lblNumbers, lblPageCount);
        }
        else
        {
            gv.DataSource = null;
            gv.DataBind();
            ViewState["numbers"] = "0";
            div_pager.Visible = false;
        }
    }

    private void Bind()
    {
        Bind(GetList().Tables[0], gvitem);
    }
    #endregion

    #region gridview中的事件

    #region RowDataBound事件 protected void gvitem_RowDataBound(object sender, GridViewRowEventArgs e)
    protected void gvitem_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        //鼠标在列表行中停留时的样式
        for (int i = -1; i < gvitem.Rows.Count; i++)
        {
            //首先判断是否是数据行
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                //当鼠标停留时更改背景色
                e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#B5C9DD'");
                //当鼠标移开时还原背景色
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");

                Label Lbl_RuleReply = (Label)e.Row.FindControl("Lbl_RuleReply");
                Lbl_RuleReply.Attributes.Add("onmousesover", "document.getElementById('div_reply').style.display='';");
            }
        }

        //显示行号
        AddNo(gvitem, "lbl_No");

    }
    #endregion

    #region PageIndexChanging事件 protected void gvitem_PageIndexChanging(object sender, GridViewPageEventArgs e)
    /// <summary>
    /// PageIndexChanging事件
    /// </summary>
    protected void gvitem_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        gvitem.PageIndex = e.NewPageIndex;
    }
    #endregion

    #region 
    protected void gvitem_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        Edit(sender, e);
    }
    #endregion

    #endregion

    #region 命令按钮事件

    #region 删除事件
    protected void butDelete_Click(object sender, ImageClickEventArgs e)
    {
        ArrayList al = getIDs(gvitem, "cb_ID", "LblID");
        if (al!=null)
        {
            Delete(al);
            Bind();
        }
        else
        {
            PageError("请选择要删除的规则！", Request.RawUrl);
        }
    }

    #region 根据ID号成批删除 public virtual void DeleteBated(ArrayList myArrayList)
    /// <summary>
    /// 根据ID号成批删除
    /// </summary>
    /// <param name="al">ID号列表</param>
    public void Delete(ArrayList myArrayList)
    {
        int id;
        for (int i = 0; i < myArrayList.Count; i++)
        {
            //获取ID
            id = int.Parse(myArrayList[i].ToString());
            //删除
            ruleBO.Delete(id);
        }
    }
    #endregion
    #endregion

    #region 新增事件
    protected void ibtnxinzeng_Click(object sender, ImageClickEventArgs e)
    {
        Response.Redirect("RuleAdd.aspx");
    }
    #endregion

    #region 修改事件
    private void Edit(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "edit")
        {
            Response.Redirect("RuleEdit.aspx?RuleID=" + e.CommandArgument);
        }
    }
    #endregion

    #endregion
    
}
